package bcit.nxt.mission;

// UltrasonicPoll.java
import gin.and.tonic.*;
import lejos.nxt.Button;
import lejos.nxt.ButtonListener;

public class UtraRoadFollower implements UltrasonicListener,TouchListener
{

    private volatile boolean isRunning = true;
    Gear gear = new Gear(MotorPort.B, MotorPort.C);

    public UtraRoadFollower()
    {
        NxtRobot robot = new NxtRobot();

        UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);
       
        TouchSensor ts = new TouchSensor(SensorPort.S2);
        robot.addPart(gear);
        robot.addPart(us);
        robot.addPart(ts);
        gear.setSpeed(40);
        us.addUltrasonicListener(this,30);
        ts.addTouchListener(this);
        

        gear.backward();
        
    }

    public void far(SensorPort port, int level)
    {
        gear.backward();
    }

    public void near(SensorPort port, int level)
    {
        gear.rightArc(1.5);
    }

    public void pressed(SensorPort port)
    {
        gear.forward(500);
        gear.rightArc(1.5);

    }


   public void released(SensorPort port)
   {
       gear.backward();
   }

    public static void main(String[] args)
    {
        new UtraRoadFollower();
    }
}
